<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<link href="../../css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../../js/jquery.js"></script>
<script type="text/javascript" src="../../js/axios.js"></script>
<script type="text/javascript" src="../../js/api.js"></script>
</head>

<body>
<div class="place"> <span>位置：</span>
  <ul class="placeul">
    <li>采购管理</li>
    <li>商品类型管理</li>
    <li>修改</li>
  </ul>
</div>
<div class="formbody">
  <div class="formtitle"><span>商品类型信息</span></div>
  <form id="form">
    <ul class="forminfo">
      <li>
        <label>品牌名称</label>
        <select class="dfselect" id="brand" name="brandName">
          <option>请选择</option>
          <option>联想</option>
          <option>海尔</option>
        </select>
        <i>必选</i>
      </li>
      <li>
        <label>商品类型名称</label>
        <input name="typeName" type="text" class="dfinput" id="typeName"/>
        <i class="tips">必填，不能超过50个字符</i>
      </li>
      <li>
        <label>状态</label>
        <select class="dfselect" name="typeStatus" id="typeStatus">
          <option value="1">可用</option>
          <option value="2">不可用</option>
        </select>
        <i>必选</i>
      </li>
      <li>
        <label>创建人</label>
        <input name="createId" type="hidden" id="createId" value="101"/>
        <input name="createName" type="text" id="createName" value="马云" readonly="readonly" class="roinput" />
        <i>不能编辑</i>
      </li>
      <li>
        <label>创建时间</label> <!--value="2017-11-18 15:36:10" readonly="readonly"-->
        <input name="createTime" id="createTime" class="roinput" readonly="readonly"/>
        <i>不能编辑</i>
      </li>
      <li>
        <label>&nbsp;</label>
        <input name="" type="submit" class="btn" value="确定"/>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <input name="" type="button" class="btn" value="返回" onclick="window.location.href='productTypeList.html'"/>
      </li>
    </ul>
  </form>
</div>
<script type="text/javascript">
  //获取id
  let typeId=getParameter("id");
  $(function () {
    brandname();
    $('#typeName').blur(check);//光标验证

    $('#form').submit(function () {
      let type=$('#form').serializeArray();
      if (check()){
        axiosJson(
                'get',//提交方法
                '/purchase/alterType',//提交地址
                type,
                {typeId:typeId}
        ).then((res) => {
          location.href="productTypeList.html";
        })
      }
      return false;
    })

  })

  //表单验证
  function check() {
    let typeName=$('#typeName').val();
    if (typeName==null||typeName==''){
      $('.tips').html("商品名称不能为空").css("color","red");
      return false;
    }
    return true;
  }

  //品牌信息
  function brandname() {
    axiosJson(
            'get',//提交方法
            '/purchase/brandName',//提交地址
            null,
            null
    ).then((res) => {
      let audit = res.data.resultData
      let str='<option value="">请选择</option>'
      for (let i=0;i<audit.length;i++){
        str+='<option>'+audit[i]+'</option>'
      }
      $('#brand').html(str)
      //数据回显
      echo();
    })
  }

  // 数据回显
  function echo() {
    axiosJson(
            'get',//提交方法
            '/purchase/typePage',//提交地址
            null,
            {typeId:typeId}
    ).then((res) => {
      let audit = res.data.resultData.data[0];
      $('#brand').val(audit.brand.brandName);
      $('#typeName').val(audit.typeName);
      $('#typeStatus').val(audit.typeStatus);
      $('#createId').val(audit.createId);
      $('#createName').val(audit.creator.uName);
      $('#createTime').val(audit.createTime);
    })
  }

</script>
</body>
</html>
